package org.tokaf.bestcolumnfinder;

import org.tokaf.algorithm.Algorithm;
import org.tokaf.datasearcher.DataSearcher;

/**
 * <p>Performs parallel search. All columns have same number of accesses+-1.</p>
 * <p>Copyright (c) 2006</p>
 * @author Alan Eckhardt
 * @version 1.0
 */
public class SimpleColumnFinder implements BestColumnFinder {
	public SimpleColumnFinder() {
	}

	int i = -1;

	/**
	 * findColumn
	 * @param alg Algorithm
	 * @return int
	 */
	public int findColumn(Algorithm alg) {
		DataSearcher[] data = alg.getDataSearchers();
		if (i >= data.length)
			i = 0;
		i++;
		if (i >= data.length)
			i = 0;
		while (i < data.length && !data[i].hasNext())
			i++;
		if (i >= data.length) {
			i = 0;
			while (i < data.length && !data[i].hasNext())
				i++;
		}

		if (i >= data.length) {
			return -1;
		}
		return i;
	}

}
